function alergi_add(){
	$("#btn-alergi").click(function(){
		var html = "<tr>";		
		html += "<td><input type='text' name='alergi[]' class='form-control input-sm'/></td>";
		html += "<td><input type='text' name='alergi_ket[]' class='form-control input-sm'/></td>";
		html += "<td><button class='btn btn-xs btn-danger' onclick='destroy_row(this)'><i class='fa fa-fw fa-trash'></i></button></td>";
		$("#alergi-section").append(html);
	});
}

function r_penyakit_add(){
	$("#btn-r-penyakit").click(function(){
		var html = "<tr>";		
		html += "<td><input type='text' name='penyakit[]' class='form-control input-sm'/></td>";
		html += "<td><input type='text' name='keterangan[]' class='form-control input-sm'/></td>";
		html += "<td><button class='btn btn-xs btn-danger' onclick='destroy_row(this)'><i class='fa fa-fw fa-trash'></i></button></td>";
		$("#r-penyakit-section").append(html);
	});
}

function r_keluarga_add() {
	$("#btn-r-keluarga").click(function(){
		var html = "<tr>";		
		html += "<td><input type='text' name='keluarga[]' class='form-control input-sm'/></td>";
		html += "<td><input type='text' name='keterangan[]' class='form-control input-sm'/></td>";
		html += "<td><button class='btn btn-xs btn-danger' onclick='destroy_row(this)'><i class='fa fa-fw fa-trash'></i></button></td>";
		$("#r-keluarga-section").append(html);
	});
}

function r_sosial_add() {
	$("#btn-r-sosial").click(function(){
		var html = "<tr>";		
		html += "<td><input type='text' name='sosial[]' class='form-control input-sm'/></td>";
		html += "<td><input type='text' name='keterangan[]' class='form-control input-sm'/></td>";
		html += "<td><button class='btn btn-xs btn-danger' onclick='destroy_row(this)'><i class='fa fa-fw fa-trash'></i></button></td>";
		$("#r-sosial-section").append(html);
	});
}

function destroy_row(obj){
	if (confirm('Anda yakin ingin menghapus baris ini ?')) {
		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	}
}

$(document).ready(function(){
	alergi_add();
	r_penyakit_add();
	r_keluarga_add();
	r_sosial_add();

	//toggle `popup` / `inline` mode
  $.fn.editable.defaults.mode = 'inline'
  //make username editable
  $('.editme').editable();
})